﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using gametest.DxAPI;

namespace gametest.sprites
{
    public class RoTrung : sprite
    {
        private DxImageObject imageRoTrung = null;
       
        private const double SPEED = 0.5;
        private bool collision = false;
        private Stopwatch stopwatch=null;


        public double XAxis
        {
            get { return X_Axis; }
        }

        public double YAxis
        {
            get { return Y_Axis; }
        }

        public int Width
        {
            get { return imageRoTrung.Width; }
        }
        public int Height
        {
            get { return imageRoTrung.Height; }
        }

        public RoTrung() { }
        public RoTrung(DxInitGraphics g)
            : base(g)
        {
            imageRoTrung = new DxImageObject("Images\\Ro.png", BitmapType.TRANSPARENT, 0xFFFFFF, graphics.DDDevice);
            X_Axis = imageRoTrung.XPosition = (graphics.Target.Width - imageRoTrung.Width) / 2;
            Y_Axis = imageRoTrung.YPosition = graphics.Target.Height - imageRoTrung.Height - 10;
        }

        public override void Draw()
        {
            if (!collision)
                imageRoTrung.DrawBitmap(graphics.RenderSurface);
            else
            {
                if (stopwatch.ElapsedMilliseconds < 5)
                {
                    //en en
                }
                else
                {
                    collision = false;
                    stopwatch.Stop();

                }
            }
            //throw new NotImplementedException();
        }

        public override void Restore(DxInitGraphics g)
        {
            graphics = g;
            imageRoTrung.RestoreSurface();
            //throw new NotImplementedException();
        }

        public void MoveLeft(double dLoopDuration)
        {
            if (!collision)
            {
                X_Axis = imageRoTrung.XPosition;
                X_Axis -= SPEED * dLoopDuration;
                if (X_Axis < 0)
                    X_Axis = 0;
                imageRoTrung.XPosition = X_Axis;
            }
        }

        public void MoveRight(double dLoopDuration)
        {
            if (!collision)
            {
                X_Axis = imageRoTrung.XPosition;
                X_Axis += SPEED * dLoopDuration;
                if (X_Axis > (graphics.Target.Width - imageRoTrung.Width))
                    X_Axis = graphics.Target.Width - imageRoTrung.Width;
                imageRoTrung.XPosition = X_Axis;
            }
        }

        public void SetCollision()
        {
            if (!collision)
            {
                collision = true;
                stopwatch = Stopwatch.StartNew();
            }
        }
    }
}
